package org.rslai.tcedit.business.impl;

import java.io.Serializable;
import org.rslai.tcedit.dao.CaseStateDao;
import org.rslai.tcedit.dao.CatalogDao;
import org.rslai.tcedit.dao.EntityTableDao;
import org.rslai.tcedit.dao.ExecuteStateDao;
import org.rslai.tcedit.dao.ProductDao;
import org.rslai.tcedit.dao.ProductUserDao;
import org.rslai.tcedit.dao.RoleDao;
import org.rslai.tcedit.dao.TestCaseDao;
import org.rslai.tcedit.dao.TestCaseHistoryDao;
import org.rslai.tcedit.dao.UserDao;
import org.rslai.tcedit.dao.UserDetailsDao;
import org.rslai.tcedit.dao.VersionDao;
import org.rslai.tcedit.domain.CaseState;
import org.rslai.tcedit.domain.Catalog;
import org.rslai.tcedit.domain.ExecuteState;
import org.rslai.tcedit.domain.Product;
import org.rslai.tcedit.domain.ProductUser;
import org.rslai.tcedit.domain.Role;
import org.rslai.tcedit.domain.TestCase;
import org.rslai.tcedit.domain.TestCaseHistory;
import org.rslai.tcedit.domain.User;
import org.rslai.tcedit.domain.UserDetails;
import org.rslai.tcedit.domain.Version;

public abstract class AbstractBaseService {

	protected RoleDao roleDao;
	protected UserDao userDao;
	protected UserDetailsDao userDetailsDao;
	protected CaseStateDao caseStateDao;
	protected ExecuteStateDao executeStateDao;
	protected ProductDao productDao;
	protected ProductUserDao productUserDao;
	protected VersionDao versionDao;
	protected CatalogDao catalogDao;
	protected TestCaseDao testCaseDao;
	protected TestCaseHistoryDao testCaseHistoryDao;
	protected EntityTableDao entityTableDao;

	/**
	 * @spring.property ref="roleDao"
	 */
	public void setRoleDao(RoleDao roleDao) {
		this.roleDao = roleDao;
	}

	/**
	 * @spring.property ref="userDao"
	 */
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	/**
	 * @spring.property ref="userDetailsDao"
	 */
	public void setUserDetailsDao(UserDetailsDao userDetailsDao) {
		this.userDetailsDao = userDetailsDao;
	}

	/**
	 * @spring.property ref="caseStateDao"
	 */
	public void setCaseStateDao(CaseStateDao caseStateDao) {
		this.caseStateDao = caseStateDao;
	}

	/**
	 * @spring.property ref="executeStateDao"
	 */
	public void setExecuteStateDao(ExecuteStateDao executeStateDao) {
		this.executeStateDao = executeStateDao;
	}

	/**
	 * @spring.property ref="productDao"
	 */
	public void setProductDao(ProductDao productDao) {
		this.productDao = productDao;
	}

	/**
	 * @spring.property ref="productUserDao"
	 */
	public void setProductUserDao(ProductUserDao productUserDao) {
		this.productUserDao = productUserDao;
	}

	/**
	 * @spring.property ref="versionDao"
	 */
	public void setVersionDao(VersionDao versionDao) {
		this.versionDao = versionDao;
	}

	/**
	 * @spring.property ref="catalogDao"
	 */
	public void setCatalog(CatalogDao catalogDao) {
		this.catalogDao = catalogDao;
	}

	/**
	 * @spring.property ref="testCaseDao"
	 */
	public void setTestCaseDao(TestCaseDao testCaseDao) {
		this.testCaseDao = testCaseDao;
	}

	/**
	 * @spring.property ref="testCaseHistoryDao"
	 */
	public void setTestCaseHistoryDao(TestCaseHistoryDao testCaseHistoryDao) {
		this.testCaseHistoryDao = testCaseHistoryDao;
	}

	/**
	 * @spring.property ref="entityTableDao"
	 */
	public void setEntityTableDao(EntityTableDao entityTableDao) {
		this.entityTableDao = entityTableDao;
	}

	public void create(Object object) {
		if (object instanceof Role) {
			roleDao.create((Role) object);
		} else if (object instanceof User) {
			throw new IllegalArgumentException("不支持此对象调用 create 方法: " + object.getClass().getName());
		} else if (object instanceof UserDetails) {
			userDetailsDao.create((UserDetails) object);
		} else if (object instanceof CaseState) {
			caseStateDao.create((CaseState) object);
		} else if (object instanceof ExecuteState) {
			executeStateDao.create((ExecuteState) object);
		} else if (object instanceof Product) {
			throw new IllegalArgumentException("不支持此对象调用 create 方法: " + object.getClass().getName());
		} else if (object instanceof ProductUser) {
			productUserDao.create((ProductUser) object);
		} else if (object instanceof Version) {
			throw new IllegalArgumentException("不支持此对象调用 create 方法: " + object.getClass().getName());
		} else {
			throw new IllegalArgumentException("create 方法不支持此对象: " + object.getClass().getName());
		}
	}

	public void create(String productID, Object object) {
		if (object instanceof Catalog) {
			catalogDao.create(productID, (Catalog) object);
		} else if (object instanceof TestCase) {
			testCaseDao.create(productID, (TestCase) object);
		} else if (object instanceof TestCaseHistory) {
			testCaseHistoryDao.create(productID, (TestCaseHistory) object);
		} else {
			throw new IllegalArgumentException("create 方法不支持此对象: " + object.getClass().getName());
		}
	}

	public void delete(Object object) {
		if (object instanceof Role) {
			roleDao.delete((Role) object);
		} else if (object instanceof User) {
			userDao.delete((User) object);
		} else if (object instanceof UserDetails) {
			userDetailsDao.delete((UserDetails) object);
		} else if (object instanceof CaseState) {
			caseStateDao.delete((CaseState) object);
		} else if (object instanceof ExecuteState) {
			executeStateDao.delete((ExecuteState) object);
		} else if (object instanceof Product) {
			productDao.delete((Product) object);
		} else if (object instanceof ProductUser) {
			productUserDao.delete((ProductUser) object);
		} else if (object instanceof Version) {
			versionDao.delete((Version) object);
		} else if (object instanceof Catalog) {
			throw new IllegalArgumentException("delete 方法不支持此对象: " + object.getClass().getName());
		} else if (object instanceof TestCase) {
			testCaseDao.delete((TestCase) object);
		} else if (object instanceof TestCaseHistory) {
			testCaseHistoryDao.delete((TestCaseHistory) object);
		} else {
			throw new IllegalArgumentException("delete 方法不支持此对象: " + object.getClass().getName());
		}
	}

	public void update(Object object) {
		if (object instanceof Role) {
			roleDao.update((Role) object);
		} else if (object instanceof User) {
			throw new IllegalArgumentException("不支持此对象调用 update 方法: " + object.getClass().getName());
		} else if (object instanceof UserDetails) {
			userDetailsDao.update((UserDetails) object);
		} else if (object instanceof CaseState) {
			caseStateDao.update((CaseState) object);
		} else if (object instanceof ExecuteState) {
			executeStateDao.update((ExecuteState) object);
		} else if (object instanceof Product) {
			throw new IllegalArgumentException("不支持此对象调用 update 方法: " + object.getClass().getName());
		} else if (object instanceof ProductUser) {
			productUserDao.update((ProductUser) object);
		} else if (object instanceof Version) {
			versionDao.update((Version) object);
		} else if (object instanceof Catalog) {
			catalogDao.update((Catalog) object);
		} else if (object instanceof TestCase) {
			testCaseDao.update((TestCase) object);
		} else if (object instanceof TestCaseHistory) {
			testCaseHistoryDao.update((TestCaseHistory) object);
		} else {
			throw new IllegalArgumentException("update 方法不支持此对象: " + object.getClass().getName());
		}
	}

	public Object query(Class clazz, Serializable id) {
		if (clazz == Role.class) {
			return roleDao.query(id);
		} else if (clazz == User.class) {
			return userDao.query(id);
		} else if (clazz == UserDetails.class) {
			return userDetailsDao.query(id);
		} if (clazz == CaseState.class) {
			return caseStateDao.query(id);
		} if (clazz == ExecuteState.class) {
			return executeStateDao.query(id);
		} if (clazz == Product.class) {
			return productDao.query(id);
		} if (clazz == ProductUser.class) {
			return productUserDao.query(id);
		} if (clazz == Version.class) {
			return versionDao.query(id);
		} else {
			throw new IllegalArgumentException("query 方法不支持此对象: " + clazz.getName());
		}
	}

	public Object query(String productID, Class clazz, Serializable id) {
		if (clazz == Catalog.class) {
			return catalogDao.query(productID, id);
		} else if (clazz == TestCase.class) {
			return testCaseDao.query(productID, id);
		} else if (clazz == TestCaseHistory.class) {
			return testCaseHistoryDao.query(productID, id);
		} else {
			throw new IllegalArgumentException("query 方法不支持此对象: " + clazz.getName());
		}
	}

}
